<!-- 自定义专题图表 可按照1920X1080设置固定尺寸 通过封装方法适配缩放尺寸 只可以替换数据 无其他高级属性自定义扩展
  注:业务专题图表的图片存放文件夹名称需与当前文件名一致(打包时才会将图片打包进对应文件夹中)
  (1.并在aircim.webpack.build.component.config.js配置需要打包的文件2.npm run lib_c 执行打包命令  最后的组件会打包在components/grids中) -->
<template>
  <div class="scale-box" :id="dynamicIdName()">
    <!-- 设置动态类名以及交互方法 注!! 必须设置行内样式宽高同步 -->
    <div
        class="service-icon-num-box animate__animated"
        style="width: 880px; height: 78px"
        :id="dynamicChildName()"
    >
      <div class="nums">
        <div class="num-item">
          <p class="num-text">办件评价量</p>
          <p class="num-content">
            <span class="num"><em>4684</em>条</span>
            <span class="num"><em>2345</em>%</span>
          </p>
        </div>
        <div class="num-item">
          <p class="num-text">服务人员评价量</p>
          <p class="num-content">
            <span class="num"><em>4684</em>条</span>
            <span class="num"><em>2345</em>%</span>
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
//混入封装方法
import encapsulation from "../../utils/aircimGird";

export default {
  name: "ancientCanalsLeft",
  grid_specification: "aircim_grid_1x1",
  mixins: [encapsulation],
  data() {
    return {
      resizeObserver: null,
      //动态Id
      timestamp: null,
    };
  },
  methods: {
    //初始化方法
    initGrid() {},
    //刷新数据方法
    refreshData(val) {
      this.echartdata = val.echartdata;
    },
    refreshConfig(val) {},
    //监听外部盒子的大小 然后对数据井行缩放
    scaleFn() {
      const parentBox = document.getElementById(`dynamic-${this.timestamp}`);
      const childBox = document.getElementById(
          `dynamicChild-${this.timestamp}`
      );
      const parentWidth = parentBox.offsetWidth;
      const parentHeight = parentBox.offsetHeight;
      const childWidth = childBox.offsetWidth;
      const childHeight = childBox.offsetHeight;
      let scaleX, scaleY;
      if (parentWidth < childWidth || parentHeight < childHeight) {
        const scaleBasedOnWidth = parentWidth / childWidth;
        const scaleBasedOnHeight = parentHeight / childHeight;
        scaleX = scaleBasedOnWidth;
        scaleY = scaleBasedOnHeight;
      } else {
        scaleX = parentWidth / childWidth;
        scaleY = parentHeight / childHeight;
      }
      childBox.style.transform = `scale(${scaleX}, ${scaleY})`;
    },
    // 监听盒子变化
    listenChangeFn() {
      let that = this;
      const element = document.getElementById(`dynamic-${this.timestamp}`);
      // console.log(element, "element");
      if (element) {
        new ResizeObserver(() => {
          // 处理元素大小变化的逻辑
          that.scaleFn();
        }).observe(element);
      }
    },
    // 绑定动画样式 animate__flash
    bindAnimationFn(animateName) {
      if (animateName != null) {
        this.dynamicClassName = animateName;
      }
    },
    //定义唯一ID名
    dynamicIdName() {
      return `dynamic-${this.timestamp}`;
    },
    //定义唯一ID名
    dynamicChildName() {
      return `dynamicChild-${this.timestamp}`;
    },
  },
  mounted() {
    this.timestamp = new Date().getTime();
    this.$nextTick(() => {
      // 监听盒子变化
      this.listenChangeFn();
    });
  },

  computed: {},
  // 销毁监听
  beforeDestroy() {
    // 组件销毁前停止监听
    if (this.resizeObserver) {
      this.resizeObserver.disconnect();
    }
    if (this.requestTime != null) {
      clearInterval(this.requestTime);
    }
  },
};
</script>
<style lang="scss" scoped>
@import "../../static/assets/common.scss";
</style>
<style lang="scss" scoped>
.scale-box {
  width: 100%;
  height: 100%;
  position: relative;
}

.service-icon-num-box {
  padding: 0px 10px;
  box-sizing: border-box;
  position: absolute;
  transform-origin: left top;
  display: flex;
  flex-direction: column;
}
.nums {
  display: flex;
  justify-content: space-between;
  height: 100%;
  .num-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    padding-left: 147px;
    position: relative;
    .num-content{
      display: flex;
      //justify-content: center;
      align-items: center;
      gap: 22px;
      width: 226px;
      height: 55px;
      background: url(../../static/assets/AssessIconNum/bg.png) no-repeat center center;
      background-size: cover;
    }
    &::after {
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
      content: "";
      width: 147px;
      background: url(../../static/assets/AssessIconNum/bottom.png) no-repeat
      left bottom;
      background-size: 147px 65px;
      transform-style: preserve-3d;
      animation: scalex 2s linear infinite;
    }
    &::before {
      position: absolute;
      content: "";
      width: 45px;
      height: 45px;
      left: 50px;
      top: 0;
      background-image: url(../../static/assets/AssessIconNum/icon1.png);
      background-size: cover;
      animation: transformy 2s ease-in-out infinite;
    }
    &:nth-child(2){
      &::before {
        background-image: url(../../static/assets/AssessIconNum/icon2.png);
      }
    }

    .num-text {
      line-height: 27px;
      margin-bottom: -5px;
      color: #FFF;
      font-family: "Source Han Sans CN";
      font-size: 18px;
      font-weight: 400;
    }
    .num{
      justify-content: flex-start;
      text-align: left;
      color: #96BEE0;
      font-family: "Source Han Sans CN";
      font-size: 16px;
      font-weight: 400;
      em{
        margin-right: 4px;
        color: #0FF;
        font-family: D-DIN;
        font-size: 27px;
        font-weight: 700;
      }
    }
  }
}
@keyframes transformy {
  0% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-3px);
  }
  100% {
    transform: translateY(0);
  }
}
@keyframes scalex {
  0% {
    transform: scale(0.8);
  }
  50% {
    transform: scale(1);
  }
  100% {
    transform: scale(0.8);
  }
}
</style>
